package sc.analysis.movingavg;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

import org.apache.hadoop.io.Writable;

/**
 * Used to store data between the mapper and the reducer of the moving average
 * analysis.
 * 
 * @author Quentin Rossé
 *
 */
public class MaData implements Writable{

	/**
	 * average value
	 */
	private float avg;
	
	/**
	 * previous average value (the day before)
	 */
	private float prevAvg;
	
	/**
	 * price at last close
	 */
	private float lastPrice;
	
	/**
	 * close price the day before
	 */
	private float prevPrice;
	
	/**
	 * number of values for this average
	 */
	private int num;
	
	MaData(){}
	
	public MaData(float avg, float prevAvg, float lastPrice, float prevPrice, int num){
		this.avg = avg;
		this.prevAvg = prevAvg;
		this.lastPrice = lastPrice;
		this.prevPrice = prevPrice;
		this.num = num;
	}
	
	public MaData(MaData ma){
		this.avg = ma.avg;
		this.prevAvg = ma.prevAvg;
		this.lastPrice = ma.lastPrice;
		this.prevPrice = ma.prevPrice;
		this.num = ma.num;
	}
	
	public float getAvg() {
		return avg;
	}
	
	public float getPrevAvg() {
		return prevAvg;
	}

	public float getLastPrice() {
		return lastPrice;
	}
	
	public float getPrevPrice() {
		return prevPrice;
	}

	public int getNum() {
		return num;
	}

	@Override
	public void readFields(DataInput in) throws IOException {
		avg = in.readFloat();
		prevAvg = in.readFloat();
		lastPrice = in.readFloat();
		prevPrice = in.readFloat();
		num = in.readInt();
	}

	@Override
	public void write(DataOutput out) throws IOException {
		out.writeFloat(avg);
		out.writeFloat(prevAvg);
		out.writeFloat(lastPrice);
		out.writeFloat(prevPrice);
		out.writeInt(num);
	}

}
